import random
from django.http import JsonResponse
from rest_framework.views import  APIView
from lxml import etree
from dal import models



class LineData(APIView):

    def get(self, request):
        data = {}


        res_list = []

        try:
            res_obj = models.Jingdian.objects.order_by('-rate')
            for obj in res_obj[0:5]:
                res_dict = {}
                res_dict['name'] = obj.title[0:7]
                res_dict['value'] = obj.rate
                res_list.append(res_dict)

            data['res_list'] = res_list

            return JsonResponse(data)

        except Exception as e:
            print(e)
            data['code'] = 444
            return JsonResponse(data)



